import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * I represent the records
 * @author Hugo Armando Rodríguez Flores
 * @version May 25th 2013
 */
public class Records extends Actor
{
    private UserInfo information;   //A reference to UserInfo class
    
    /**
     * Puts the records on screen, and tells the current ranking you are on.
     * @param aWorld is the current world the actors are living in
     */
    public void displayRecords(World aWorld)
    {
        int x=83, y=20, gap=30;
        java.util.List<UserInfo> bestOnes=information.getTop(4);
        if (bestOnes!=null)
        {
            for (UserInfo it: bestOnes)
            {
                aWorld.addObject(new Mensaje(it.getUserName(), 40), x, y);
                aWorld.addObject(new Mensaje(""+it.getScore(), 40), x+gap*3, y);
                y+=gap;
            }
            if (information.getMyInfo().getRank()>0)
                aWorld.addObject(new Mensaje("Your Ranking: "+information.getMyInfo().getRank(), 30), x, aWorld.getHeight()-20);
            else
                aWorld.addObject(new Mensaje("You havent hit the top!"), aWorld.getWidth()/2, aWorld.getHeight()-20);
        }
        else
            aWorld.addObject(new Mensaje("Without records"), aWorld.getWidth()/2, aWorld.getHeight()/2);
    }
    
    /**
     * Store the new scores.
     * @param points are the points the current user obtained when he/she was playing
     */
    public void storeScore(int points)
    {
        if(UserInfo.isStorageAvailable())
        {
            information=UserInfo.getMyInfo();
            if(points>information.getScore())
                information.setScore(points);
            information.store();
        }
    }
}
